********************************************************************************
*	OVERVIEW
*		This is the analysis code for the paper: 
*		"Redesigning payments for ecosystem services to increase cost-effectiveness"
*		Santiago Izquierdo-Tort, Seema Jayachandran and Santiago Saavedra
********************************************************************************

	local paper = 1
		local stats_cba = 1
		local table1 = 1
		local table2 = 1
		local table3 = 1
		local tablea1 = 1
		local tablea2 = 1
		local tablea3 = 1
		local cba = 1

	if `paper' == 1 {


	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	*				Numbers for Cost-Benefit Analysis
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *	
	
	if `stats_cba' == 1{
	*External numbers/Costeffectiveness
	global discountrate=0.03
	* Assumed effect of Standard 
	global defonoPES : dis %12.3f 0.01*((12+14.7)/2)/6
	global defonoPES_perc : dis %2.1f ${defonoPES}*100
	texdoc init "$numbers/standard_effect.tex" , replace force
			tex  ${defonoPES_perc}
			texdoc close	
		
		
		* Import data	
	use "${analysis}\analysis.dta", clear
			
		egen sumpaytre = total(payment) if treatment == 1 
		global payment_treat = r(sum)
		global payment_treat_str : dis  %12.0gc $payment_treat
		texdoc init "$numbers/payment_treat.tex" , replace force
				tex  $payment_treat_str
				texdoc close


		egen sumpaycontr = total(payment) if treatment == 0
		global payment_control = r(sum)
		global payment_control_str : dis  %12.0gc $payment_control
		texdoc init "$numbers/payment_control.tex" , replace force
				tex  $payment_control_str
				texdoc close
		

		
count if comply == 1 & treatment == 1
	local count_valuecomtreat = r(N)
	texdoc init "$numbers/count_valuecomtreat.tex" , replace force
		tex  `count_valuecomtreat'
	    texdoc close
	
	count if treatment == 1
	local count_valuetreat = r(N)
	texdoc init "$numbers/count_valuetreat.tex" , replace force
		tex  `count_valuetreat'
	    texdoc close
	
	count if comply == 1 & treatment == 0
	local count_valuecomtreat0 = r(N)
	texdoc init "$numbers/count_valuecomtreat0.tex" , replace force
		tex  `count_valuecomtreat0'
	    texdoc close

	count if treatment == 0
	local count_valuetreat0 = r(N)
	texdoc init "$numbers/count_valuetreat0.tex" , replace force
		tex  `count_valuetreat0'
	    texdoc close
		
	local percnetobs =`count_valuecomtreat0'/`count_valuetreat0'
	local controlcomplied=100*`percnetobs'
    local controlcompliedperce=round(`controlcomplied',1)
		texdoc init "$numbers/controlcompliedperce.tex" , replace force
		tex  `controlcompliedperce'\%)
	    texdoc close
	
local percnetobs =`count_valuecomtreat'/`count_valuetreat'
	local treatcompliedcom=100*`percnetobs'
    local treatcompliedpercecom=round(`treatcompliedcom',1)
		texdoc init "$numbers/treatcompliedpercecom.tex" , replace force
		tex  `treatcompliedpercecom'\%)
	    texdoc close
	

	regress comply treatment
	test treatment==0
	local pvalue= r(p) 
		local pvaluetreatcomp: dis  %5.2f `pvalue' 
        texdoc init "$numbers/pvaluetreatcomp.tex" , replace force
		tex  `pvaluetreatcomp'
	    texdoc close		
		
	}
			
		
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	*				Table 1: Treatment effects on deforestation (Pixel level)
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	
**# Table 1: Treatment effects on deforestation (Pixel level) (May 2021 - Aug/Sept 2022)
	 local table1=1
	if 	`table1' ==  1{
	* Import data	
	use "${analysis}\analysis_v4.dta", clear	
	merge 1:m code_id using "${temp}\pixel_data_final.dta", gen(merge_defor_pixellevel)	
		
		
	foreach var in forloss_augsept /*forloss_julyaug*/ {
	
	local pref=substr("`var'",-3,.)
	
 *  px_deforestation in PROPERTY pixels
	*No LDV 
	#d;
	eststo `pref'property, title(""): reghdfe `var' treatment 
								if analysis_fu==1 & property==1 , absorb(locali_bl)
								vce(cluster code_id)  keepsingletons
	;
	#d cr
	return list
	mat property=r(table)

	* Observations in Property
	local numobsproperty=e(N)
	
	sum `var'  if treatment == 1 & e(sample)
	estadd scalar mean_treat = `r(mean)'
	sum `var'  if treatment == 0 & e(sample)
	estadd scalar mean_control = `r(mean)'		
	estadd local unit ="Pixel"
	local meancontrolpropertycba: dis %5.3f r(mean)

		* Mean control property
		local meancontrolproperty: dis %5.0f r(mean)*100
		dis `meancontrolproperty'
		texdoc init "$numbers/meancontrolproperty_`var'.tex" , replace force
		tex  `meancontrolproperty'
	    texdoc close
		* Mean control property (CBA)
		local meancontrolpropertycba: dis %5.3f `meancontrolpropertycba'
		dis `meancontrolpropertycba'
		texdoc init "$numbers/meancontrolpropertycba_`var'.tex" , replace force
		tex  `meancontrolpropertycba'
	    texdoc close
		dis `meancontrolpropertycba'
		* Treatment effect
		local treateffectproperty=abs(100*e(b)[1,1])
		local treateffectproperty: dis %5.1f `treateffectproperty'
		texdoc init "$numbers/treateffectproperty_`var'.tex" , replace force
		tex  `treateffectproperty'
	    texdoc close
		* Treatment effect (cba)
		local treateffectpropertycba=e(b)[1,1]
		local treateffectpropertycba: dis %5.3f `treateffectpropertycba'
		texdoc init "$numbers/treateffectpropertycba_`var'.tex" , replace force
		tex  `treateffectpropertycba'
	    texdoc close
	* N Control
	count if treatment == 0 & e(sample)
	local N_pixelscontrol = r(N)
	scalar N_pixelscontrol = `N_pixelscontrol'
	texdoc init "$numbers/N_pixelscontrol_`var'.tex" , replace force
		tex  `N_pixelscontrol'
	    texdoc close
	* N Treatment	
	count if treatment == 1 & e(sample)
	local N_pixelstreat = r(N)
	scalar N_pixelstreat = `N_pixelstreat'
	texdoc init "$numbers/N_pixelstreat_`var'.tex" , replace force
		tex  `N_pixelstreat'
	    texdoc close
			
		* Reduction in defo : Treatment/mean
	    local percnet =`treateffectproperty'/`meancontrolproperty'
	    local lessdefores=abs(100*`percnet')
        local lessdeforestprop: dis %5.0f  `lessdefores'
		texdoc init "$numbers/lessdeforestprop_`var'.tex" , replace force
		tex  `lessdeforestprop'
	    texdoc close
		
		* Pvalue
		local pvalueproptab1=property[4,1]
		local pvalueproptab1: dis %5.2f  `pvalueproptab1'
        texdoc init "$numbers/pvalueproptab1_`var'.tex" , replace force
		tex  `pvalueproptab1'
	    texdoc close			
		
		
* px_deforestation in CONAFOR contracted pixels
	* No LDV
	#d;
	eststo `pref'conafor, title(""): reghdfe `var' treatment
							 if analysis_fu==1 & conafor==1  & property==1, 
							absorb(locali_bl) vce(cluster code_id) keepsingletons
	;
	#d cr
	return list	
	mat conafor=r(table)
	
	* Observations in Conafor
	local numobsconafor=e(N)
	
	sum `var'  if treatment == 1 & e(sample)
	global meancona_treat=r(mean)
	estadd scalar mean_treat = `r(mean)'
	sum `var'  if treatment == 0 & e(sample)
	global meancona_control=r(mean)
	estadd scalar mean_control = `r(mean)'		
	estadd local unit ="Pixel"	

		* Pvalue
		local pvalueconafortab1=conafor[4,1]
		local pvalueconafortab1: dis %5.2f  `pvalueconafortab1'
        texdoc init "$numbers/pvalueconafortab1_`var'.tex" , replace force
		tex  `pvalueconafortab1'
	    texdoc close	
		*------------------------- For Cost-Benefit Analysis -------------------*

		* Mean control conafor
	    local meancontrolcona=100*${meancona_control}
		local meancontrolcona:  dis %5.1f  `meancontrolcona'
			texdoc init "$numbers/meancontrolcona_`var'.tex" , replace force
			tex  `meancontrolcona'
			texdoc close
	
		* Difference percent pixels conafor vs property
        global obsconafor=`numobsconafor'
		global obsproperty=`numobsproperty'
		local percentobs =100*${obsconafor}/${obsproperty}
		local difpercentobs: dis %5.0f `percentobs'
		dis `difpercentobs'
		texdoc init "$numbers/difpercentsobs_`var'.tex" , replace force
		tex  `difpercentobs'
	    texdoc close
		

			global percobs =${obsconafor}/${obsproperty}
		
			local defocontrol: dis %3.1f 100*$defonoPES * ${percobs}
			dis `defocontrol'
			texdoc init "$numbers/defocontrol_`var'.tex" , replace force
			tex  `defocontrol'
			texdoc close

		local sumdefoprop =`defocontrol'+`treateffectproperty'
	    local defotreatment=`sumdefoprop'
			local defotreatment: dis %3.1f `defotreatment'
		
	    texdoc init "$numbers/defotreatment_`var'.tex" , replace force
		tex  `defotreatment'
	    texdoc close

	    local treatmenteffectconafor=100*e(b)[1,1]
		local treateffectconafor: dis %5.2f `treatmenteffectconafor'
		texdoc init "$numbers/treateffectconafor_`var'.tex" , replace force
		tex  `treateffectconafor'
	    texdoc close
		
	
		
		local Nha_enrol_control =4.588438*4.560103* `N_pixelscontrol' / 10000	
		local Nha_enrol_control: dis %5.0f `Nha_enrol_control'
		texdoc init "$numbers/Nha_enrol_control_`var'.tex" , replace force
		tex  `Nha_enrol_control'
	    texdoc close
		
		
		local Nha_enrol_treat =4.588438*4.560103* `N_pixelstreat' / 10000	
		local Nha_enrol_treat: dis %5.0f `Nha_enrol_treat'
		texdoc init "$numbers/Nha_enrol_treat_`var'.tex" , replace force
		tex  `Nha_enrol_treat'
	    texdoc close		
		

* px_deforestation in NON-CONAFOR pixels
	* No LDV
	#d;
	eststo `pref'noconafor, title(""): reghdfe `var' treatment
	                                  if 
									 analysis_fu==1 & conafor==0  & property==1, 
									 absorb(locali_bl) vce(cluster code_id) keepsingletons
	;
	#d cr
	return list
	mat nonconafor=r(table)
	* Observations in Non-Conafor
	local numobsnonconafor=e(N)
	sum `var'  if treatment == 1 & e(sample)
	local meannocona_treat= r(mean)
	estadd scalar mean_treat = `r(mean)'
	sum `var'  if treatment == 0 & e(sample)
	local meannocona_control=r(mean)
	estadd scalar mean_control = `r(mean)'		
	estadd local unit = "Pixel"
		
	* Pvalue
		local pvaluenonconafortab1=nonconafor[4,1]
		local pvaluenonconafortab1: dis %5.3f  `pvaluenonconafortab1'
        texdoc init "$numbers/pvaluenonconafortab1_`var'.tex" , replace force
		tex  `pvaluenonconafortab1'
	    texdoc close	

	    local treatmenteffectnonconafor=abs(100*nonconafor[1,1])
		local treateffectnonconafor: dis %3.1f `treatmenteffectnonconafor'
			texdoc init "$numbers/treateffectnonconafor_`var'.tex" , replace force
			tex  `treateffectnonconafor'
			texdoc close
		

		local meancontrol_nonconafor=100*`meannocona_control'
		local meancontrolnonconafor: dis %5.1f `meancontrol_nonconafor'
			texdoc init "$numbers/meancontrolnonconafor_`var'.tex" , replace force
			tex  `meancontrolnonconafor'
			texdoc close
		
        local percnet =`treateffectnonconafor'/`meancontrolnonconafor'
	    local lessdeforesnon=abs(100*`percnet')
        local lessdeforestnoncon: dis %5.0f `lessdeforesnon'
			texdoc init "$numbers/lessdeforestnoncon_`var'.tex" , replace force
			tex  `lessdeforestnoncon'
			texdoc close
			

	

	
	if "`var'"=="forloss_mayjuly" {
		local month "May/July"
	}	
	if "`var'"=="forloss_aprmay" {
		local month "April/May"
	}
	if "`var'"=="forloss_mayjune" {
		local month "May"
	}
	if "`var'"=="forloss_junejuly" {
		local month "June/July"
	}
	if "`var'"=="forloss_julyaug" {
		local month "July"
	}	
	if "`var'"=="forloss_augsept" {
		local month "August"
	}

	*** Export Table
	#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr	
	
* Layout options
	local frame0 = subinstr("`frame'", "first", "4.5cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "2.4cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "4", .)	// number of columns		
		
		#d ;
		esttab   `pref'property 
		         `pref'conafor
		         `pref'noconafor 
				using "$tables/MainTable1_`var'.tex", replace 
			style(tex) 
			booktabs star(* .1 ** .05 *** .01) se parentheses  
			nonotes label nobaselevels nomtitles collabels(none)  
			cells(b(fmt(3)) se(fmt(3) star par))   
			keep(treatment) nonumbers
			coeflabel(treatment "Treat")			
			stats(mean_control  N , fmt( 3 0)
			labels( "Control mean" 	 "N")) 
			prehead(" `prehead' &  \multicolumn{3}{c}{Deforestation May 2021 - `month' 2022} \\ \cmidrule(lr){2-4} & Property area & Conafor area & Non-Conafor area  \\  & (1) & (2) & (3) \\ ");
		#d cr 
		
	local month ""
	
	}	
	}
	
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	*				Table 2: Treatment effects at the individual level, including 
	*                        heterogeneity by baseline forest area
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	
**# Table 2: Treatment effects at the individual level, including heterogeneity by baseline forest area	
	local table2=1
	if `table2' == 1{
		
	use "${analysis}\analysis_v4.dta", clear	

	* Numbers on satisfaction
	
		* Satisfaction 	
		*Treat
		count if  analysis_fu == 1 & treat == 1 & p8_1_fu!=.
		local ttl_treat=r(N)
		count if p8_1_fu==1 & analysis_fu == 1 & treat == 1
		local satis_treat=r(N)
		local satisfactiontreat=100*`satis_treat'/`ttl_treat'
		local satisfactiontreat: dis  %5.0f  `satisfactiontreat'
		dis `satisfactiontreat'
		texdoc init "$numbers/satisfaction_treat.tex" , replace force
		tex  `satisfactiontreat'
	    texdoc close
		
		* Control
		count if  analysis_fu == 1 & treat == 0  & p8_1_fu!=.
		local ttl_control=r(N)
		count if p8_1_fu==1 & analysis_fu == 1 & treat ==0
		local satis_control=r(N)
		local satisfactioncontrol=100*`satis_control'/`ttl_control'
		local satisfactioncontrol: dis  %3.0f  `satisfactioncontrol'
		dis `satisfactioncontrol'
		texdoc init "$numbers/satisfaction_control.tex" , replace force
		tex  `satisfactioncontrol'
	    texdoc close
		
		* Total
		count if  analysis_fu == 1  & treat == 1
		local ttlt=r(N)
		count if p8_1_fu==1 & analysis_fu == 1  & treat == 1
		local satist=r(N)
		local satisfactiont=100*`satist'/`ttlt'
		local satisfactiont: dis  %3.0f  `satisfactiont'

		
		count if  analysis_fu == 1  & treat == 0
		local ttlc=r(N)
		count if p8_1_fu==1 & analysis_fu == 1  & treat == 0
		local satisc=r(N)
		local satisfactionc=100*`satisc'/`ttlc'	
		local satisfactionc: dis  %3.0f  `satisfactionc'

		dis "`satisfactiont' == `satisfactionc'"
		assert `satisfactiont' == `satisfactionc'
		local satisfaction =`satisfactiont'
		local satisfaction: dis  %5.0f  `satisfaction'
		dis `satisfaction'
		texdoc init "$numbers/satisfaction.tex" , replace force
		tex  `satisfaction'
	    texdoc close	
		
		* Attrition
		count if analysis_fu==1
			local ttl_lndowners=r(N)
			local ttl_lndowners: dis  %3.0f  `ttl_lndowners'
			dis `ttl_lndowners'
			texdoc init "$numbers/ttl_lndowners.tex" , replace force
			tex  `ttl_lndowners'
			texdoc close	
					
		count if attritor==0
			local ttl_nonattrit=r(N)
			local ttl_nonattrit: dis  %3.0f  `ttl_nonattrit'
			dis `ttl_nonattrit'
			texdoc init "$numbers/ttl_nonattrit.tex" , replace force
			tex  `ttl_nonattrit'
			texdoc close		
		

	sum px_predfor_may2021_property, d
		gen d_prop_forest=(px_predfor_may2021_property>`r(p50)') if px_predfor_may2021_property!=.
		la var d_prop_forest "Forest area in property above median"

foreach yvar in  augsept {

* Individual level
{	
	
* px_deforestation as share of property area
	#d;
	eststo defo_`yvar'_property, title(""): reghdfe px_defp2_`yvar'_property i.treatment 
	                                        if analysis_fu==1, absorb(locali_bl) vce(robust) keepsingletons
	;
	#d cr
	
	sum  px_defp2_`yvar'_property  if treatment == 1 & e(sample)
	estadd scalar mean_treat = `r(mean)'
	sum px_defp2_`yvar'_property  if treatment == 0 & e(sample)
	estadd scalar mean_control = `r(mean)'			
	
	
*  px_deforestation as share of conafor area
	#d;
	eststo defo_`yvar'_conafor, title(""): reghdfe px_defp2_`yvar'_conafor i.treatment 
	                                 if analysis_fu==1, absorb(locali_bl ) vce(robust) keepsingletons
	;
	#d cr
	sum px_defp2_`yvar'_conafor  if treatment == 1 & e(sample)
	estadd scalar mean_treat = `r(mean)'
	sum px_defp2_`yvar'_conafor  if treatment == 0 & e(sample)
	estadd scalar mean_control = `r(mean)'			

	

* px_deforestation as share of non-conafor area
	#d;
	eststo defo_`yvar'_noconafor, title(""): reghdfe px_defp2_`yvar'_nocona i.treatment 
	                                  if analysis_fu==1, absorb(locali_bl ) vce(robust) keepsingletons
	;
	#d cr
	sum px_defp2_`yvar'_nocona  if treatment == 1 & e(sample)
	estadd scalar mean_treat = `r(mean)'
	sum px_defp2_`yvar'_nocona  if treatment == 0 & e(sample)
	estadd scalar mean_control = `r(mean)'		
	
}
	
	* Heterogeneity
		//Dummy above median property area +  dummy above median property area with forest + dummy above forest area
	if "`yvar'"=="aprmay" {
		local month "April/May"
	}
	if "`yvar'"=="mayjune" {
		local month "May"
	}
	if "`yvar'"=="junejuly" {
		local month "June/July"
	}	
	if "`yvar'"=="julyaug" {
		local month "July"
	}
	if "`yvar'"=="augsept" {
		local month "August"
	}
	local k=1
	foreach var in  d_prop_forest {
	
	clonevar hetvar=`var'
	

 *px_deforestation as share of property area
	#d;
	eststo `var'_`yvar'_p, title(""): reghdfe px_defp2_`yvar'_property i.treatment##i.hetvar 
	                                        if analysis_fu==1, absorb(locali_bl) vce(robust) keepsingletons
	;
	#d cr
	
	sum px_defp2_`yvar'_property  if treatment == 1 & e(sample)
	estadd scalar mean_treat = `r(mean)'
	sum px_defp2_`yvar'_property  if treatment == 0 & e(sample)
	estadd scalar mean_control = `r(mean)'			
		* Significance
		test _b[1.treatment] + _b[1.treatment#1.hetvar]=0
		local sig : dis %12.3f r(p) 
		estadd local pval=`sig'		
		

		lincom 1.treatment + 1.treatment#1.hetvar 
		local pvalue= r(p) 
		local pvaluetreatabove: dis  %5.3f `pvalue'
        texdoc init "$numbers/pvaluetreatabove_`yvar'.tex" , replace force
		tex  `pvaluetreatabove'
	    texdoc close	
		
		local propforest=100*e(b)[1,4]
		local d_prop_forestpval: dis  %5.2f `propforest'
		 


local perc=100*e(b)[1,8]
		local d_prop_forest: dis  %5.2f  `perc'
		texdoc init "$numbers/d_prop_forest_`yvar'.tex" , replace force
		tex  `d_prop_forest'
	    texdoc close	

local perctreat=100*e(b)[1,2]
		local d_prop_trea: dis  %5.2f  `perctreat'
		texdoc init "$numbers/d_prop_trea_`yvar'.tex" , replace force
		tex  `d_prop_trea'
	    texdoc close	
		
		
local percn =abs(`d_prop_forest'+`d_prop_trea') // Changed for "+"
	local changepptab2= `percn'
    local changepercntab2: dis  %5.1f `changepptab2'
		
		texdoc init "$numbers/changepercntab2_`yvar'.tex" , replace force
		tex  `changepercntab2'
	    texdoc close	
	
		 
*  px_deforestation as share of conafor area
	#d;
	eststo `var'_`yvar'_c, title(""): reghdfe px_defp2_`yvar'_conafor i.treatment##i.hetvar 
	                                 if analysis_fu==1, absorb(locali_bl) vce(robust) keepsingletons
	;
	#d cr
	sum px_defp2_`yvar'_conafor  if treatment == 1 & e(sample)
	estadd scalar mean_treat = `r(mean)'
	sum px_defp2_`yvar'_conafor  if treatment == 0 & e(sample)
	estadd scalar mean_control = `r(mean)'			
		* Significance
		test _b[1.treatment] + _b[1.treatment#1.hetvar]=0
		local sig : dis %12.3f r(p) 
		if `sig'==0.000{
		estadd local pval="$<0.001$"			
		}
		else {
		estadd local pval="`sig'"				
		}

* px_deforestation as share of non-conafor area
	#d;
	eststo `var'_`yvar'_nc, title(""): reghdfe px_defp2_`yvar'_nocona i.treatment##i.hetvar 
	                                  if analysis_fu==1, absorb(locali_bl ) vce(robust) keepsingletons
	;
	#d cr
	sum px_defp2_`yvar'_nocona  if treatment == 1 & e(sample)
	estadd scalar mean_treat = `r(mean)'
	sum px_defp2_`yvar'_nocona  if treatment == 0 & e(sample)
	estadd scalar mean_control = `r(mean)'		
		* Significance
		test _b[1.treatment] + _b[1.treatment#1.hetvar]=0
		local sig : dis %12.3f r(p) 
		if `sig'==0.000{
		estadd local pval="$<0.001$"			
		}
		else {
		estadd local pval="`sig'"				
		}

			
	local ++k
	drop hetvar

	if "`var'"=="d_prop_forest" {
		local label "Above-median forest area at baseline"
		local intlabel  "Treat $\times$ Above-median forest area at baseline"	
	}

	
	*** Export Table
#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr	
	
	* Layout options
	local frame0 = subinstr("`frame'", "first", "7cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "1.2cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "6", .)	// number of columns		
		#d ;
		esttab	defo_`yvar'_property  `var'_`yvar'_p
				defo_`yvar'_conafor   `var'_`yvar'_c  
		        defo_`yvar'_noconafor  `var'_`yvar'_nc
		using "$tables/MainTable2_`var'`yvar'.tex", replace 
			style(tex) 
			booktabs star(* .1 ** .05 *** .01) se parentheses  
			nonotes label nobaselevels nomtitles collabels(none)   nonumbers
			cells(b(fmt(3)) se(fmt(3) star par))   
			keep(1.treatment#1.hetvar 1.treatment 1.hetvar) order( 1.treatment  1.treatment#1.hetvar 1.hetvar)
			coeflabel(1.treatment "Treat" 1.treatment#1.hetvar "`intlabel'"  1.hetvar "`label'" ) 
			stats(mean_control  pval N , fmt( 3 3 0)
			labels( "Control mean"  "p-val: Treat + Treat $\times$ `label' = 0" "N")) 
			prehead(" `prehead' & \multicolumn{6}{c}{Deforestation May 2021 - `month' 2022} \\ \cmidrule(lr){2-7} &  \multicolumn{2}{c}{Property area} & \multicolumn{2}{c}{Conafor area} & \multicolumn{2}{c}{Non-Conafor area}  \\ \cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7} & (1) & (2) & (3) & (4) & (5) & (6)  \\ ");
		#d cr 	
	}	
	
	}
	}
	
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	*				Table 3: Balance in baseline
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	
**# Table 3: Balance in baseline
		
	
	if `table3' == 1{
	use "${analysis}\analysis_v4.dta", clear	
			
	clonevar prev_prop=px_defp_previous_property
	clonevar prev_cona=px_defp_previous_conafor
	clonevar prev_noncona=px_defp_previous_nocona	
	
#d;
	global descvars1   genero_12_1_bl 
					   grado_15_1_bl 
					   ln_gasto_22_bl
					   /*PSA_enrolledland_perc_bl*/
					   benfi_psa_d_bl
			           					   
	;
	#d cr	
	
	
#d;
	global descvars2   size_land_ha_48_tot_bl 
					   dist_carr_210_bl 
					   /*prev_prop*/
					   prev_cona
					   prev_noncona
					   /*area_loss_perc_avg_bl
					   desmonte_423_bin_bl
					   ganado_455_perc_bl
					   ganado_455_bin_bl*/
					   forest_area_total_bl
	;
	#d cr			
	

	
#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr
	
	* Layout options
	local frame0 = subinstr("`frame'", "first", "8cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "1.5cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "6", .)	// number of columns	
	

file open sumstat using "$tables/MainTable3_balance.tex", write replace 
file write sumstat "`prehead'" _n      // table header
file write sumstat " Variable & Total & Treatment & Control & Standardized diff    \\     " _n       
file write sumstat " & (1) & (2) & (3) & (4) \\     " _n   
file write sumstat "\midrule \addlinespace[10pt]" _n 

foreach var in $descvars1 $descvars2 {

	local varlab: variable label `var'  
	
	if "`var'" == "better_farmer" local varlab "Agree: Even boys who will become farmers will be better at farming if they have gone to school."
	if "`var'" == "ln_gasto_22_bl" local varlab "Household expenditure in last month (Ln)"
	if "`var'" == "benfi_16_1_bl" local varlab "Had enrolled previously in a PSA program"
	if "`var'" == "dist_carr_210_bl" local varlab "Distance to road (minutes)"
	if "`var'" == "desmonte_423_bin_bl" local varlab "Deforested in last 3 years"
	if "`var'" == "prev_prop" local varlab "Previous def. \% property area"
	if "`var'" == "prev_cona" local varlab "Previous def. \% Conafor area"
	if "`var'" == "prev_noncona" local varlab "Previous def. \% Non- Conafor area"
	
	sum `var' if treatment!=.
	local totalmean: di %7.3f `r(mean)'	
	local totalsd: di %7.3f `r(sd)'
	
	sum `var' if treatment == 1 
	local treatmean: di %7.3f `r(mean)'	
	local treatsd: di %7.3f `r(sd)'
	
	sum `var' if treatment == 0 
	local controlmean: di %7.3f `r(mean)'	
	local controlsd: di %7.3f `r(sd)'
	
	gen stand_diff = (`treatmean'-`controlmean')/ `totalsd'
	if `totalsd' == 0 replace stand_diff = 0
	sum stand_diff
	local diff: di %7.3f `r(mean)'
	
	foreach x in treatsd controlsd totalsd diff {   
		local `x'=trim(string(``x'',"%7.3f"))
	}

	file write sumstat " `varlab' & \makecell[b]{`totalmean' \\ {(}`totalsd'{)}} & \makecell[b]{`treatmean' \\ {(}`treatsd'{)}} & \makecell[b]{ `controlmean' \\ {(}`controlsd'{)}}  & `diff'   \\ \addlinespace[3pt]    " _n  

	drop stand_diff

}


preserve

		local descvars_flags
		foreach y in $descvars1 $descvars2 {
				cap confirm variable `y'_flag,exact
				if !_rc{
					replace `y'=. if `y'_flag
					drop `y'_flag
				}
				qui count if mi(`y')
				if r(N)!=0{
					gen `y'_flag=mi(`y')
					egen x = mean (`y') 
					qui replace `y'=x if `y'_flag==1
					drop x
					local descvars_flags `descvars_flags' `y'_flag
					
				}	
		}

		areg treatment $descvars1 $descvars2 `descvars_flags' , absorb(locali_bl) vce(robust)
		testparm $descvars1 $descvars2
		local p_val1: di %7.3f r(p)
		local n1: di %9.0g e(N)
restore

sum treatment 
local tot_obs = r(N)
sum treatment if treatment == 1
local treat_obs = r(N)
sum treatment if treatment == 0 
local control_obs = r(N)

file write sumstat " \hline Number of observations & `tot_obs' & `treat_obs' & `control_obs' & \\ " _n
*file write sumstat " Joint p-value & \multicolumn{4}{c}{`p_val1'} \\ " _n
file write sumstat " \bottomrule " _n
file write sumstat " \end{tabular} }"

file close sumstat	


* Soft coded stats
		* Gender
		sum genero_12_1_bl 
		local gender= r(mean)*100
		local gender: dis  %5.0f  `gender'
		texdoc init "$numbers/summstats_gender.tex" , replace force
		tex  `gender'
	    texdoc close	
		* Enrolled in conafor
		sum benfi_psa_d_bl 
		local enrolled= r(mean)*100
		local enrolled: dis  %5.0f  `enrolled'
		texdoc init "$numbers/summstats_previouslyenrolled.tex" , replace force
		tex  `enrolled'
	    texdoc close	
		* Land
		sum size_land_ha_48_tot_bl 
		local land= r(mean)
		local land: dis  %5.0f  `land'
		texdoc init "$numbers/summstats_land.tex" , replace force
		tex  `land'
	    texdoc close	
		* Forest
		sum forest_area_total_bl 
		local forest= r(mean)
		local forest: dis  %3.0f  `forest'
		texdoc init "$numbers/summstats_forest.tex" , replace force
		tex  `forest'
	    texdoc close
		* Years of education
		sum grado_15_1_bl 
		local educ= r(mean)
		local educ: dis  %3.0f  `educ'
		texdoc init "$numbers/summstats_educ.tex" , replace force
		tex  `educ'
	    texdoc close
		* HH expenditure (MX)
		sum ln_gasto_22_bl 
		local exp= exp(r(mean))
		local exp= round(`exp', 100)
		local final : dis %9.0fc `exp'
		texdoc init "$numbers/summstats_expenditures.tex" , replace force
		tex  `final'
	    texdoc close		

		* HH expenditure (usd)
		local expusd=`exp'/20.036
		local expusd: dis  %3.0f  `expusd'
		texdoc init "$numbers/summstats_expenditures_usd.tex" , replace force
		tex  `expusd'
	    texdoc close			
	}   
		
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	*				Table A.1: Compliance
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	
**# Table A.1: Compliance

	if `tablea1' == 1{
		
	use "${analysis}\analysis_v4.dta", clear	
	clonevar prev_prop=px_defp_previous_property
	clonevar prev_cona=px_defp_previous_conafor
	clonevar prev_noncona=px_defp_previous_nocona	
		
	#d;
	global descvars1   genero_12_1_bl 
					   grado_15_1_bl 
					   ln_gasto_22_bl
					   /*PSA_enrolledland_perc_bl*/
					   benfi_psa_d_bl
			           attritor					   
	;
	#d cr	
	
	
#d;
	global descvars2   size_land_ha_48_tot_bl 
					   dist_carr_210_bl 
					   /*prev_prop*/
					   prev_cona
					   prev_noncona
					   /*area_loss_perc_avg_bl
					   desmonte_423_bin_bl
					   ganado_455_perc_bl
					   ganado_455_bin_bl*/
					   forest_area_total_bl
	;
	#d cr			

#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr
	
	* Layout options
	local frame0 = subinstr("`frame'", "first", "8cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "1.5cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "6", .)	// number of columns	
	

file open sumstat using "$tables/MainTableA1_compliance.tex", write replace 
file write sumstat "`prehead'" _n      // table header
file write sumstat " Variable & Total & Met PES conditions & Did not meet conditions  & Standardized diff    \\     " _n       
file write sumstat " & (1) & (2) & (3) & (4) \\     " _n   
file write sumstat "\midrule \addlinespace[10pt]" _n 

foreach var in $descvars1 $descvars2 {

	local varlab: variable label `var'  
	
	if "`var'" == "better_farmer" local varlab "Agree: Even boys who will become farmers will be better at farming if they have gone to school."
	if "`var'" == "ln_gasto_22_bl" local varlab "Household expenditure in last month (Ln)"
	if "`var'" == "benfi_16_1_bl" local varlab "Had enrolled previously in a PSA program"
	if "`var'" == "dist_carr_210_bl" local varlab "Distance to road (minutes)"
	if "`var'" == "desmonte_423_bin_bl" local varlab "Deforested in last 3 years"
	if "`var'" == "prev_prop" local varlab "Previous def. \% property area"
	if "`var'" == "prev_cona" local varlab "Previous def. \% Conafor area"
	if "`var'" == "prev_noncona" local varlab "Previous def. \% Non- Conafor area"
	if "`var'" == "attritor" local varlab "Attrition"
	
	sum `var' if comply!=.
	local totalmean: di %7.3f `r(mean)'	
	local totalsd: di %7.3f `r(sd)'
	
	sum `var' if comply == 1 
	local treatmean: di %7.3f `r(mean)'	
	local treatsd: di %7.3f `r(sd)'
	
	sum `var' if comply == 0 
	local controlmean: di %7.3f `r(mean)'	
	local controlsd: di %7.3f `r(sd)'
	
	gen stand_diff = (`treatmean'-`controlmean')/ `totalsd'
	if `totalsd' == 0 replace stand_diff = 0
	sum stand_diff
	local diff: di %7.3f `r(mean)'
	
	foreach x in treatsd controlsd totalsd diff {   
		local `x'=trim(string(``x'',"%7.3f"))
	}

	file write sumstat " `varlab' & \makecell[b]{`totalmean' \\ {[}`totalsd'{]}} & \makecell[b]{`treatmean' \\ {[}`treatsd'{]}} & \makecell[b]{ `controlmean' \\ {(}`controlsd'{)}}  & `diff'   \\ \addlinespace[3pt]    " _n  

	drop stand_diff

}
preserve
	local descvars_flags
		foreach y in $descvars1 $descvars2 {
				cap confirm variable `y'_flag,exact
				if !_rc{
					replace `y'=. if `y'_flag
					drop `y'_flag
				}
				qui count if mi(`y')
				if r(N)!=0{
					gen `y'_flag=mi(`y')
					egen x = mean (`y') 
					qui replace `y'=x if `y'_flag==1
					drop x
					local descvars_flags `descvars_flags' `y'_flag
					
				}	
		}

		areg comply $descvars1 $descvars2 `descvars_flags' , absorb(locali_bl) vce(robust)
		testparm $descvars1 $descvars2
		local p_val1: di %7.3f r(p)
			local n1: di %9.0g e(N)
	restore
	sum comply 
	local tot_obs = r(N)
	sum comply if comply == 1
	local treat_obs = r(N)
	sum comply if comply == 0 
	local control_obs = r(N)

	file write sumstat "\hline Number of observations & `tot_obs' & `treat_obs' & `control_obs' & \\ " _n
	*file write sumstat " Joint p-value & \multicolumn{4}{c}{`p_val1'} \\ " _n
	file write sumstat " \bottomrule " _n
	file write sumstat " \end{tabular} }"

	file close sumstat		
		
	}
	
	
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	*				Table A.2: Robustness - Treatment effects on deforestation 
	*                          (Pixel level). Controlling for past deforestation
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	
	
**# Table A.2: Robustness - Treatment effects on deforestation (Pixel level). Controlling for past deforestation
	
	if 	`tablea2' ==  1{
	* Import data	
	use "${analysis}\analysis_v4.dta", clear	
	merge 1:m code_id using "${temp}\pixel_data_final.dta", gen(merge_defor_pixellevel)	

		
	
		
foreach var in  forloss_augsept {
		
	local pref=substr("`var'",-3,.)
 *  px_deforestation in PROPERTY pixels
	*No LDV 
	#d;
	eststo property, title(""): reghdfe `var' treatment  px_defp_previous_property
								if analysis_fu==1 & property==1 , absorb(locali_bl)
								vce(cluster code_id)  keepsingletons
	;
	#d cr
	
	sum `var'  if treatment == 1 & e(sample)
	estadd scalar mean_treat = `r(mean)'
	sum `var'  if treatment == 0 & e(sample)
	estadd scalar mean_control = `r(mean)'		
	estadd local unit ="Pixel"
	


* px_deforestation in CONAFOR contracted pixels
	* No LDV
	#d;
	eststo conafor, title(""): reghdfe `var' treatment px_defp_previous_conafor
							 if analysis_fu==1 & conafor==1  & property==1, 
							absorb(locali_bl) vce(cluster code_id) keepsingletons
	;
	#d cr
	sum `var'  if treatment == 1 & e(sample)
	global meancona_treat=r(mean)
	estadd scalar mean_treat = `r(mean)'
	sum `var'  if treatment == 0 & e(sample)
	global meancona_control=r(mean)
	estadd scalar mean_control = `r(mean)'		
	estadd local unit ="Pixel"	
	
	
* px_deforestation in NON-CONAFOR pixels
	* No LDV
	#d;
	eststo noconafor, title(""): reghdfe `var' treatment px_defp_previous_nocona
	                                  if 
									 analysis_fu==1 & conafor==0  & property==1, 
									 absorb(locali_bl) vce(cluster code_id) keepsingletons
	;
	#d cr
	
	sum `var'  if treatment == 1 & e(sample)
	estadd scalar mean_treat = `r(mean)'
	sum `var'  if treatment == 0 & e(sample)
	estadd scalar mean_control = `r(mean)'		
	estadd local unit = "Pixel"
	
	if "`var'"=="forloss_mayjuly" {
		local month "May/July"
	}	
	if "`var'"=="forloss_aprmay" {
		local month "April/May"
	}
	if "`var'"=="forloss_mayjune" {
		local month "May"
	}
	if "`var'"=="forloss_junejuly" {
		local month "June/July"
	}
	if "`var'"=="forloss_julyaug" {
		local month "July"
	}	
	if "`var'"=="forloss_augsept" {
		local month "August"
	}

	*** Export Table
	#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr	
	
* Layout options
	local frame0 = subinstr("`frame'", "first", "4.5cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "2.4cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "4", .)	// number of columns		
		
		#d ;
		esttab   property 
		         conafor
		         noconafor 
				using "$tables/MainTableA2_`var'.tex", replace 
			style(tex) 
			booktabs star(* .1 ** .05 *** .01) se parentheses  
			nonotes label nobaselevels nomtitles collabels(none)  
			cells(b(fmt(3)) se(fmt(3) star par))   
			keep(treatment) nonumbers
			coeflabel(treatment "Treat")			
			stats(mean_control  N , fmt( 3 0)
			labels( "Control mean" 	 "N")) 
			prehead(" `prehead' &  \multicolumn{3}{c}{Deforestation May 2021 - `month' 2022} \\ \cmidrule(lr){2-4} & Property area & Conafor area & Non-Conafor area  \\  & (1) & (2) & (3) \\ ");
		#d cr 
		
	local month ""
	
	}	
	}
		
	
			

	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	*				Cost-Benefit Analysis
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *	
	
	if `cba' == 1{
	
foreach var in  forloss_augsept  {
eststo clear
estimates clear
clear
*External numbers/Costeffectiveness
	global discountrate=0.03
	* Assumed effect of Standard 
	global defonoPES : dis %12.3f 0.01*((12+14.7)/2)/6
	global defonoPES_perc : dis %2.1f ${defonoPES}*100
	texdoc init "$numbers/standard_effect.tex" , replace force
			tex  ${defonoPES_perc}
			texdoc close	
	
*----------------------*
* Input external values
*----------------------*

	* Assumed effect of Standard
	import delimited "$numbers/standard_effect.tex", clear
	levelsof v1, local(standard_effect)
	*local standard_effect: dis substr(`standard_effect',1,3)
	local standard_effect=`standard_effect'/100
	global standard_effect : dis %5.3f `standard_effect'
	
	* Tons of CO2/ha
	global tons_co2 : dis %5.3f 150*3.6667
	local tons_co2:  dis %5.0f $tons_co2
	texdoc init "$numbers/tons_co2.tex" , replace force
				tex  `tons_co2'
				texdoc close
				
	* Interest rate
	global interest_rate : dis %5.2f 0.03
	* Pesos to USD conversion rate
	global rate_pesos_usd : dis %5.3f 20.036
	* Hectares/pixel
	global hect_per_pix : dis %12.8f 4.588438*4.560103/10000	
	
	
*--------------------------------------*
* Input calculated values from our data
*--------------------------------------*

	
	* % Partial enroll
		import delimited "$numbers/difpercentsobs_`var'.tex", clear
		levelsof v1, local(enroll)
		dis `enroll'
		local enroll=`enroll'/100
		global enroll : dis %5.2f `enroll'
		
	* Standard PES mean
		quietly import delimited "$numbers/meancontrolpropertycba_`var'.tex", clear
		levelsof v1, local(pes_mean)
		local pes_mean=`pes_mean'
		global pes_mean : dis %5.3f `pes_mean'

	* Treatment effect
		quietly import delimited "$numbers/treateffectpropertycba_`var'.tex", clear	
		sum
		local  treat_effect=abs(r(mean))
		global treat_effect : dis %5.3f `treat_effect'

	* Total payments to treatment group
		quietly import delimited "$numbers/payment_treat.tex", clear delimiter(" ")
		gen value=regexr(v1,",","")
		destring value, replace
		drop v1
		quietly sum
		global treat_pay : dis %5.0f r(mean)
	
	* Total payments to control group
		quietly import delimited "$numbers/payment_control.tex", clear delimiter(" ")
		gen value=regexr(v1,",","")
		destring value, replace
		drop v1
		quietly sum
		global control_pay : dis %5.0f r(mean)
		
	* Forest pixels at baseline (full property)
		* Control
		quietly import delimited "$numbers/N_pixelscontrol_`var'.tex", clear
		sum
		global n_pix_property_control : dis %5.0f r(mean)
				
		* Treatment
		quietly import delimited "$numbers/N_pixelstreat_`var'.tex", clear
		sum
		global n_pix_property_treat : dis %5.0f r(mean)
			
		
			
*--------------------------------*
* Calculated values
*--------------------------------*

	* Standard effect on all property
	global standard_effect_property : dis %5.3f ${standard_effect}*${enroll}
	* No PES rate
	global no_pes_rate : dis %5.3f ${pes_mean}+${standard_effect_property}
	texdoc init "$numbers/noPESrate_`var'.tex" , replace force
				tex  $no_pes_rate
				texdoc close
	local nopesrate_perc:  dis %5.1f  ${no_pes_rate}*100
	texdoc init "$numbers/noPESrate_perc_`var'.tex" , replace force
				tex  `nopesrate_perc'
				texdoc close

	* Years left of forest, from BL
	global forest_yrs_left : dis %3.1f 1/${no_pes_rate}
			texdoc init "$numbers/forest_yrs_left_`var'.tex" , replace force
			tex  $forest_yrs_left
			texdoc close

	
	* Discount factor
	global discount_factor: dis %5.2f 1-1/(1+${interest_rate})^${forest_yrs_left}
		local interest_rate_str : dis $interest_rate
		local forest_yrs_left_str : dis $forest_yrs_left
		local discount_factor_str : dis %3.2f $discount_factor	
	texdoc init "$numbers/discount_factor_`var'.tex" , replace force
			tex  $discount_factor
			texdoc close	
	local discount_factor_perc : dis %3.0f  ${discount_factor}*100
	texdoc init "$numbers/discount_factor_perc_`var'.tex" , replace force
			tex `discount_factor_perc'
			texdoc close		
	global damage_incurred: dis %3.0f 100*1/(1+${interest_rate})^${forest_yrs_left}
	texdoc init "$numbers/damage_incurred_perc_`var'.tex" , replace force
			tex $damage_incurred
			texdoc close	
********************************************************************************
*						Analysis
********************************************************************************


		

	* Hectares of forest at baseline (full property)
		* Control
			global hect_bl_control : dis %5.0f ${hect_per_pix}*${n_pix_property_control}
			
		* Treatment
			global hect_bl_treat : dis %5.0f ${hect_per_pix}*${n_pix_property_treat}
		


	* Avoided % deforestation in a year
		* Control	
			global avoided_defo_control : dis %5.3f ${standard_effect_property}
		
		* Treatment
			global avoided_defo_treat : dis %5.3f ${avoided_defo_control}+${treat_effect}
		

	* Hectares of averted deforestation
	
		* Control
			global hec_averted_defo_control : dis %5.1f ${hect_bl_control}*${avoided_defo_control}
				texdoc init "$numbers/Nhaavdcontrol_`var'.tex" , replace force
				tex  $hec_averted_defo_control
				texdoc close
		* Treatment
			global hec_averted_defo_treat : dis %5.1f ${hect_bl_treat}*${avoided_defo_treat}
				texdoc init "$numbers/Nhaavdtreatment_`var'.tex" , replace force
				tex  $hec_averted_defo_treat
				texdoc close
	

	* MX$ to avert a hectare of deforestation
			
		* Control
		global mx_avert_defo_control : dis %5.0f ${control_pay}/${hec_averted_defo_control}
		global mx_avert_defo_control_str : dis  %8.0gc $mx_avert_defo_control
				texdoc init "$numbers/MXperhacontrol_`var'.tex" , replace force
				tex  $mx_avert_defo_control_str
				texdoc close				
		* Treatment
		global mx_avert_defo_treat : dis %5.0f ${treat_pay}/${hec_averted_defo_treat}
		global mx_avert_defo_treat_str : dis  %9.0gc $mx_avert_defo_treat
				texdoc init "$numbers/MXperhatreatment_`var'.tex" , replace force
				tex  $mx_avert_defo_treat_str
				texdoc close				
	
	* USD to avert a hectare of deforestation
			
		* Control
		global usd_avert_defo_control : dis %5.0f ${mx_avert_defo_control}/${rate_pesos_usd}
		global usd_avert_defo_controlstr : dis %5.0f ${mx_avert_defo_control}/${rate_pesos_usd}
				texdoc init "$numbers/USDper_hecadv_control_`var'.tex" , replace force
				tex  $usd_avert_defo_controlstr
				texdoc close

		* Treatment
		global usd_avert_defo_treat : dis %5.0f ${mx_avert_defo_treat}/${rate_pesos_usd}
		global usd_avert_defo_treatstr : dis %7.0gc ${mx_avert_defo_treat}/${rate_pesos_usd}
				texdoc init "$numbers/USDper_hecadv_treat_`var'.tex" , replace force
				tex  $usd_avert_defo_treatstr
				texdoc close

	

	* Cost-effectiveness ratio
	
		global cost_effectiveness_ratio : dis  %5.1f  ${usd_avert_defo_control}/${usd_avert_defo_treat}
				texdoc init "$numbers/Costeffectiveness_`var'.tex" , replace force
				tex  $cost_effectiveness_ratio
				texdoc close
	
	* USD per ton of averted CO2
	
		global usd_ton_co2_averted : dis %5.2f ${usd_avert_defo_treat}/${tons_co2}
				texdoc init "$numbers/USDpertonCO2nodisc_`var'.tex" , replace force
				tex  $usd_ton_co2_averted
				texdoc close

	* USD per ton of averted CO2 (with discount factor)
	
		global usd_ton_co2_averted_disc : dis %5.2f ${usd_ton_co2_averted}/${discount_factor}
				texdoc init "$numbers/USDpertonCO2_`var'.tex" , replace force
				tex  $usd_ton_co2_averted_disc
				texdoc close

	}
	}
	}	
